D:\git\skunkworks\herald-for-cpp\herald-tests\test-templates.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2021 Herald Project Contributors |
2 | | // SPDX-License-Identifier: Apache-2.0 |
3 | | // |
4 | | |
5 | | #ifndef HERALD_TESTS_TEMPLATES_H |
6 | | #define HERALD_TESTS_TEMPLATES_H |
7 | | |
8 | | #include "herald/herald.h" |
9 | | |
10 | | #include <iostream> |
11 | | |
12 | | class BlankDevice : public herald::Device { |
13 | | public: |
14 | 4 | BlankDevice() : id(herald::datatype::Data(std::byte(10),6)) {}; |
15 | 4 | ~BlankDevice() = default; |
16 | | |
17 | 0 | herald::datatype::Date created() const { |
18 | 0 | return herald::datatype::Date(14); |
19 | 0 | } |
20 | 0 | herald::datatype::TimeInterval timeIntervalSinceLastUpdate() const { |
21 | 0 | return herald::datatype::TimeInterval(12); |
22 | 0 | } |
23 | 0 | const herald::datatype::TargetIdentifier& identifier() const { |
24 | 0 | return id; |
25 | 0 | } |
26 | 0 | void identifier(const herald::datatype::TargetIdentifier& toCopyFrom) {} |
27 | | |
28 | | private: |
29 | | herald::ble::TargetIdentifier id; |
30 | | }; |
31 | | |
32 | | struct TimeSetPlatformType { |
33 | | TimeSetPlatformType() |
34 | 0 | : seconds(0) {} |
35 | | |
36 | 0 | herald::datatype::Date getNow() noexcept { |
37 | 0 | return herald::datatype::Date(seconds); |
38 | 0 | } |
39 | | |
40 | | long seconds; |
41 | | }; |
42 | | |
43 | | struct DummyLoggingSink { |
44 | 21 | DummyLoggingSink() : subsystem(), category(), value() {} |
45 | 21 | ~DummyLoggingSink() = default; |
46 | | |
47 | 108 | void log(const std::string& sub,const std::string& cat,herald::data::SensorLoggerLevel level, std::string message) { |
48 | 108 | value = sub + "," + cat + "," + message; |
49 | 108 | std::cout << "DummyLoggingSink::log: " << value << std::endl; |
50 | 108 | subsystem = sub; |
51 | 108 | category = cat; |
52 | 108 | } |
53 | | |
54 | | std::string subsystem; |
55 | | std::string category; |
56 | | std::string value; |
57 | | }; |
58 | | |
59 | | class DummyBluetoothStateManager : public herald::ble::BluetoothStateManager { |
60 | | public: |
61 | 21 | DummyBluetoothStateManager() = default; |
62 | 21 | ~DummyBluetoothStateManager() = default; |
63 | | |
64 | 0 | void add(herald::ble::BluetoothStateManagerDelegate& delegate) override { |
65 | 0 | ; // no op |
66 | 0 | } |
67 | | |
68 | 0 | herald::ble::BluetoothState state() override { |
69 | 0 | return herald::ble::BluetoothState::poweredOn; |
70 | 0 | } |
71 | | }; |
72 | | |
73 | | |
74 | | class DummyBLEDBDelegate : public herald::ble::BLEDatabaseDelegate { |
75 | | public: |
76 | | DummyBLEDBDelegate() : updateCallbackCalled(false), createCallbackCalled(false), |
77 | 2 | deleteCallbackCalled(false), dev(), attr() {} |
78 | 2 | ~DummyBLEDBDelegate() {} |
79 | | |
80 | | // overrides |
81 | 5 | void bleDatabaseDidCreate(const herald::ble::BLEDevice& device) override { |
82 | 5 | createCallbackCalled = true; |
83 | 5 | dev.emplace(device); |
84 | 5 | } |
85 | | |
86 | | void bleDatabaseDidUpdate(const herald::ble::BLEDevice& device, |
87 | 6 | const herald::ble::BLEDeviceAttribute attribute) override { |
88 | 6 | updateCallbackCalled = true; |
89 | 6 | dev.emplace(device); |
90 | 6 | attr.emplace(attribute); |
91 | 6 | } |
92 | | |
93 | 2 | void bleDatabaseDidDelete(const herald::ble::BLEDevice& device) override { |
94 | 2 | deleteCallbackCalled = true; |
95 | 2 | dev.emplace(device); |
96 | 2 | } |
97 | | |
98 | | bool updateCallbackCalled; |
99 | | bool createCallbackCalled; |
100 | | bool deleteCallbackCalled; |
101 | | std::optional<std::reference_wrapper<const herald::ble::BLEDevice>> dev; |
102 | | std::optional<herald::ble::BLEDeviceAttribute> attr; |
103 | | }; |
104 | | |
105 | | #endif |